package com.tuanzi.webtalk.controller;


import com.tuanzi.webtalk.domain.GroupKey;
import com.tuanzi.webtalk.domain.Group_info;
import com.tuanzi.webtalk.domain.User;
import com.tuanzi.webtalk.service.FriendService;
import com.tuanzi.webtalk.service.GroupService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 雄关漫道真如铁，而今迈过从头越
 **/

/**
 * 这里是写聊天页面信息的
 */

@Controller
public class IndexInfoController {

    @Resource
    private FriendService friendService;

    @Resource
    private GroupService groupService;

    /**
     * 这个是获取用户信息
     */
    @RequestMapping(value = "/index/user")
    @ResponseBody
    public User indexInfo(HttpSession session){
        User user = (User) session.getAttribute("user");
        return user;
    }


    /**
     * 获取用户的朋友信息   这里返回一个集合，用来统计所有的朋友
     */
    @RequestMapping(value = "/index/friends")
    @ResponseBody
    public List<User> getFriends(HttpSession session){
        User user = (User) session.getAttribute("user");
        List<User> friends = friendService.getFriends(user.getId());
        return friends;
    }

    /**
     * 获取用户加入的群聊
     */
    @RequestMapping(value = "/index/group")
    @ResponseBody
    public List<Group_info> getGroups(HttpSession session){

        User user = (User) session.getAttribute("user");

        List<Group_info> group_infos = groupService.getGroups(user.getId());

        return group_infos;
    }

}
